import 'package:flutter/material.dart';

class Search extends StatefulWidget {
  @override
  _SearchState createState() => _SearchState();
}

class _SearchState extends State<Search> {
  var _expansionList = {
    '北京': ['朝阳', '朝阳', '朝阳', '朝阳', '朝阳', '朝阳', '朝阳', '朝阳'],
    '上海': ['朝阳', '朝阳', '朝阳', '朝阳', '朝阳', '朝阳', '朝阳', '朝阳', '朝阳'],
    '福建': ['朝阳', '朝阳', '朝阳', '朝阳', '朝阳', '朝阳', '朝阳', '朝阳', '朝阳'],
    '浙江': ['朝阳', '朝阳', '朝阳', '朝阳', '朝阳', '朝阳', '朝阳', '朝阳', '朝阳']
  };

  List<Widget> _fliter() {
    List<Widget> arr = [];
    _expansionList.keys.forEach((key) {
      arr.add(parents(key, _expansionList[key]));
    });
    return arr;
  }

  Widget parents(String title, List<String> children) {
    return ExpansionTile(
      //收纳盒子
      title: Text(title),
      children: children
          .map(
            (e) => childItem(e),
          )
          .toList(),
    );
  }

  Widget childItem(String title) {
    return FractionallySizedBox(
      // 可伸缩的盒子
      widthFactor: 1, //宽度占满
      child: Text(title),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: ListView(
          children: _fliter(),
        ),
      ),
    );
  }
}
